python iterate columns

38

python iterate columns -

for (columnName, columnData) in df.iteritems():
    print('Column Name : ', columnName)
    print('Column Contents : ', columnData.values)
    
# OUTPUT
#Column Name :  ID
#Column Contents :  [1 2 3]
#Column Name :  NAME
#Column Contents :  ['John' 'James' 'Ana']

pandas iterate columns -

for name, values in df.iteritems():
    print('{name}: {value}'.format(name=name, value=values[0]))

Comments

Submit
0 Comments